	Ext.BLANK_IMAGE_URL = "../script/ext-2.0.2/resources/images/default/s.gif"; 
	var storeResourcesTop = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
        	url: 'roleResources!getResourcesTop.action?dateTime='+new Date().getTime()
        }),
        reader: new Ext.data.JsonReader({
            root: 'ZANY',
            fields:["key","value"]
        }),
        remoteSort: true
    });
    
    var storeRole = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
        	url: 'roleResources!getRole.action?dateTime='+new Date().getTime()
        }),
        reader: new Ext.data.JsonReader({
            root: 'ZANY',
            fields:["key","value"]
        }),
        remoteSort: true
    });
    
    storeResourcesTop.load();
    storeRole.load();
    var resourcesSelect = new Ext.form.ComboBox({
		 			id:'resourcesValue',
		 			name:'resourcesValue',
			        forceSelection:true,
			        store: storeResourcesTop,
			        hiddenName: 'resourceCode',
			        valueField:'key',
			        displayField:'value',
			        typeAhead: true,
			        mode: 'local',
			        resizable:true,
			        triggerAction: 'all',
			        emptyText:'请选择功能模块...',
			        selectOnFocus:true,
			        width:120
			    });
	
	var roleSelect = new Ext.form.ComboBox({
		 			id:'roleValue',
		 			name:'roleValue',
			        forceSelection:true,
			        store: storeRole,
			        hiddenName: 'resourceCode',
			        valueField:'key',
			        displayField:'value',
			        typeAhead: true,
			        mode: 'local',
			        resizable:true,
			        triggerAction: 'all',
			        emptyText:'请选择角色...',
			        selectOnFocus:true,
			        width:120
			    });
			    
	var resources = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
        	url: 'roleResources!getResources.action?dateTime='+new Date().getTime()
        }),
        reader: new Ext.data.JsonReader({
            root: 'ZANY',
            totalProperty: "results",
            fields:["resourceName","resourceCode"]
        }),
        sortInfo:{field:'resourceCode', direction:'ASC'},// 排序信息
        remoteSort: true
    });
    
    function addRoleResource(){
		if(gridResources.getSelectionModel().hasSelection()) {
	       		var records = gridResources.getSelectionModel().getSelected();
	       		var roleCode = roleSelect.getValue();
	       		if(roleCode==''){
	       			ZANY.util.Msg('提示信息',"请选择角色！");
	       			return false;
	       		}
	       		var resourceCode = records.data["resourceCode"];
	       		//Ext.MessageBox.confirm('Message','确认添加['+resourceName+']么？',function(btn){
	        	//if(btn == 'yes'){	
		           Ext.Ajax.request({url:'roleResources!insertRoleResource.action?dateTime='+new Date().getTime(),
		                params:{resourceCode: resourceCode, roleCode: roleCode},
		                success:function(response, options){
		                   	var response = Ext.util.JSON.decode(response.responseText);
							if(response.success){
						        Ext.getCmp('resources').getStore().reload(); //刷新Grid
								selinforole();
							}else if(!response.success){
								ZANY.util.Msg('信息',"添加权限功能失败，如有问题请联系系统管理员！"+response.msg);  
							}             
		                }
		        	});
				//}
			//})
	       		
	       }
	}

    var roleResources = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
        	url: 'roleResources!getRoleResources.action?dateTime='+new Date().getTime()
        }),
        reader: new Ext.data.JsonReader({
            root: 'ZANY',
            totalProperty: "results",
            fields:["resourceName","resourceCode"]
        }),
        sortInfo:{field:'resourceCode', direction:'ASC'},// 排序信息
        remoteSort: true
    });
    
	var colResources=new Ext.grid.ColumnModel([      
				{header:"功能名称",dataIndex:"resourceName",width:100,sortable:true}
				]);
	
	var sm = new Ext.grid.CheckboxSelectionModel();
	
	var colRoleResources=new Ext.grid.ColumnModel([sm,   
				{header:"权限功能",dataIndex:"resourceName",width:100,sortable:true}
				]);
	
	var oneTbar = new Ext.Toolbar({   
        items: ['-',{text:'&nbsp;&nbsp;查&nbsp;&nbsp;询&nbsp;&nbsp;',iconCls:'yes',handler:selinfo}
        	   ]   
    });
    
	var gridResources = new Ext.grid.GridPanel({
        collapsible: true,
        animCollapse: false,
		id:'resources',
		ddGroup: 'resourcesGroup',
		height:800,
		stripeRows :true,
		enableDragDrop   : true,
        stripeRows       : true,
		cm: colResources,
		loadMask: {msg:'正在加载功能模块信息，请稍侯……'}, 
		layout: 'fit',
		viewConfig: {
            forceFit:true
        },
		store: resources,
		tbar:['-',new Ext.form.Label({text:'功能模块名称:'}),resourcesSelect],
		listeners:{  
			'render':function(){   
				oneTbar.render(this.tbar); //add one tbar        
			}
		},
		bbar:new Ext.PagingToolbar({
            pageSize: 20,
            store: resources,
            displayInfo: true,
            displayMsg: '',
        	emptyMsg:'没有记录'
        })
	});
	
	var twoTbar = new Ext.Toolbar({   
        items: ['-',{text:'&nbsp;&nbsp;查&nbsp;&nbsp;询&nbsp;&nbsp;',iconCls:'yes',handler:selinforole},
                '-',{text:'&nbsp;&nbsp;删&nbsp;&nbsp;除&nbsp;&nbsp;',iconCls:'remove',handler: delinfo}
        	   ]   
    });
    
	var gridRoleResources = new Ext.grid.GridPanel({
		id:'gridRoleResources',
		height:500,
		stripeRows :true,
		bodyStyle:'width:100%',
        disableSelection:true,
		cm: colRoleResources,
		viewConfig: {
            forceFit:true
        },
		store: roleResources,
		iconCls: 'details',
		animCollapse: true,
		trackMouseOver:false, 
        loadMask: {msg:'正在加载[权限功能]信息，请稍侯……'},
		selModel:sm, 
		tbar:['-',new Ext.form.Label({text:'角色:'}),'-',roleSelect],
		listeners:{  
			'render':function(){   
				twoTbar.render(this.tbar); //add one tbar        
			}
		},
		bbar: new Ext.PagingToolbar({
            pageSize: 20,
            store: roleResources,
            displayInfo: true,
        	emptyMsg:'没有记录'
        })
	});
	
	function delinfo(){
		if (Ext.getCmp("gridRoleResources").getSelectionModel().hasSelection()) {
			Ext.MessageBox.confirm('Message','请问您真的要删除所选数据么？',function(btn){
        	if(btn == 'yes'){	
	            var ids = new Array();
	            var records = Ext.getCmp("gridRoleResources").getSelectionModel().getSelections();
	            for (var i = 0, len = records.length; i < len; i++) {
	                ids[i] = records[i].data["resourceCode"];
	            }
	            var roleCode = roleSelect.getValue();
	            Ext.Ajax.request({url:'roleResources!delete.action?dateTime='+new Date().getTime(),
	                params:{delId:ids,roleCode:roleCode},
	                success:function(response, options){
	                   var response = Ext.util.JSON.decode(response.responseText);
						if(response.success){
					        Ext.getCmp('gridRoleResources').getStore().reload(); //刷新Grid
	                    	ZANY.util.Msg('信息',"删除权限功能成功！");
						}else if(!response.success){
							ZANY.util.Msg('信息',"删除权限功能失败，如有问题请联系系统管理员！");  
						}             
	                }
	        	});
			}
		})}else{
			ZANY.util.Msg('提示信息',"请选择功能权限后再删除！");   
		}
	}
	
	function selinfo(){
		var topCode =resourcesSelect.getValue();
        var params={};
        params.topCode = topCode;
        resources.baseParams=params;
        resources.load({
        	callback : function(r, options, success) {   
		        if (success == false) {   
		            Ext.Msg.alert("错误", store.reader.jsonData.msg);
		        }   
		    }
		});
	}
	
	function selinforole(){
		var roleCode =roleSelect.getValue();
        var params={};
        params.roleCode = roleCode;
        roleResources.baseParams=params;
        roleResources.load({
        	callback : function(r, options, success) {   
		        if (success == false) {   
		            Ext.Msg.alert("错误", store.reader.jsonData.msg);
		        }   
		    }
		});
	}
	var onePanel = new Ext.Panel({
				id:'onePanel',
				split:true,
				layout: 'fit',
				minWidth: 100,
				minHeight: 100,
				collapsible: true,
				width:300,
				items:[gridResources],
				title :'[功能模块]信息',
				region:'west'
	});
	
	var twoPanel = new Ext.Panel({
				split:true,
				minWidth: 100,
				minHeight: 100,
				collapsible: true,
				layout: 'fit',
				title :'[角色权限]信息',
				items:[gridRoleResources],
				region:'center'
	});
				
	Ext.onReady(function(){
		Ext.QuickTips.init(); 
	　　   Ext.form.Field.prototype.msgTarget = 'side';
		new Ext.Viewport({
			layout:'border',//表格布局
			defaults:{autoScroll: true},
			items: [onePanel,twoPanel]
		});
		
		var formPanelDropTargetEl =  gridRoleResources.getView().el.dom.childNodes[0].childNodes[1];
	    var formPanelDropTarget = new Ext.dd.DropTarget(formPanelDropTargetEl, {
			ddGroup     : 'resourcesGroup',
			notifyEnter : function(ddSource, e, data) {
			},
			notifyDrop  : function(ddSource, e, data){
				addRoleResource();
				return(true);
			}
		}); 	
	})